package com.mogu_soup.util;

import java.awt.*;

/**
 * Version: 2.1
 * Author: TangJun
 * Date: 2024-08-03
 * Note:工具类，生成随机数，随机颜色，创建图片等
 */
public class MyUtil {
    private MyUtil(){}//私有化构造方法，不可被实例化

    //获取随机整数
    public static int getRandomInt(int min, int max) {
        return (int)(Math.random() * (max - min) + min);
    }

    //获取随机颜色
    public static Color getRandomColor() {
        int red = getRandomInt(0, 256);//0~255的色度
        int green = getRandomInt(0, 256);
        int blue = getRandomInt(0, 256);
        return new Color(red, green, blue);
    }
    //获取随机名字
    public static String getRandomName() {
        int name = getRandomInt(0, Constant.NAMES.length);
        int modify = getRandomInt(0, Constant.MODIFY.length);
        return Constant.MODIFY[modify] + Constant.NAMES[name];
    }
    //加载图片
    public static Image createImage(String fileName) {
        return Toolkit.getDefaultToolkit().createImage(fileName);
    }
}
